<template>
	<view class="delay-list upload-credential upload-credential-sign" :class="{'upload-credential-sign-company':companyCode&&companyCode.length}">
		<view class="base-info">
			<view class="uni-mb-5 delay-item">
				<view class="uni-flex uni-row">
					<view class="text uni-flex left-logo">
						<image :src="airImageUrl" mode="widthFix"></image>
					</view>
					<view class="uni-flex uni-column right-info">
						<view class="uni-flex" style="justify-content: space-between;">
							<view class="text title" style="flex: 1;">
								{{data.flightNo}}
							</view>
							<view class="text uni-flex right-status">
								<text class="status" style="background-color:#0c6eb7" v-if="data.aOrD=='A'">进港</text>
								<text class="status" style="background-color:#FF9800" v-if="data.aOrD=='D'">出港</text>
							</view>
						</view>
						<view class="uni-flex uni-row">
							<view class="date">航班日期：{{data.flightDate}}</view>
							<view style="padding:0 5px;position: relative;top: 2px;margin-top: -5px;"
								@tap="toggleMoreInfo=!toggleMoreInfo"><uni-icons type="down" size="16"
									color="#999"></uni-icons></view>
						</view>

					</view>
				</view>
				<view v-if="toggleMoreInfo">
					<view class="uni-flex uni-row dest" style="margin-top: 5px;"
						v-if="data.planeNo&&data.originC&&data.destC">
						<view class="item" v-if="data.planeNo">
							<view class="val">{{data.planeNo}}</view>
							<text class="label">机号</text>
						</view>
						<view class="item" v-if="data.originC">
							<view class="val">{{data.originC}}</view>
							<text class="label">出发地</text>
						</view>
						<view class="item" v-if="data.destC">
							<view class="val">{{data.destC}}</view>
							<text class="label">目的地</text>
						</view>
					</view>
					<!-- <view class="uni-flex uni-row dest" v-if="data.dpTime&&data.deTime">
						<view class="item" v-if="data.dpTime">
							<view class="val">{{data.dpTime}}</view>
							<text class="label">计划起飞时间</text>
						</view>
						<view class="item" v-if="data.deTime">
							<view class="val">{{data.deTime}}</view>
							<text class="label">预计起飞时间</text>
						</view>
					</view> -->
				</view>
			</view>
			<view class="menu-tab" v-if="companyCode == null || companyCode.length==0">
				<uni-segmented-control key="menuTab" :current="currentMenuTab" :values="menuTab" style-type="text"
					active-color="#0c6eb7" @clickItem="onClickItemMenuTab" />
			</view>
		</view>

		<!-- 上传凭证 显示 的内容 -->
		<view class="uni-pb-15" v-if="currentMenuTab === '上传凭证'">
			<view class="uni-common-mt segmented-small" style="margin:0 10px;margin-top: 10rpx;">
				<uni-segmented-control key="pingzheng" :current="current" :values="items" style-type="button"
					active-color="#0c6eb7" @clickItem="onClickItem" />
			</view>
			<view class="content">
				<view v-if="current === 'nonCash'">
					<uni-section title="授权书" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.authorization"
								:autoUpload="true" :uploadUrl="getUploadUrl('authorization')" :uploadCount="20"
								@successImage="successImage($event,0,'authorization')"
								@successDeleteImg="successDeleteImg($event,'authorization')" />
						</view>
					</uni-section>
					<uni-section title="确认单" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.confirmation" :autoUpload="true"
								:uploadUrl="getUploadUrl('confirmation')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,0,'confirmation')"
								@successDeleteImg="successDeleteImg($event,'confirmation')" />
						</view>
					</uni-section>
					<uni-section title="名单报" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.names" :autoUpload="true"
								:uploadUrl="getUploadUrl('names')" :deleteUrl="baseUrl+'sys/common/upload?token='+token"
								types="image" :uploadCount="20" @successImage="successImage($event,0,'names')"
								@successDeleteImg="successDeleteImg($event,'names')" />
						</view>
					</uni-section>
					<uni-section title="身份证复印件" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.idCards" :autoUpload="true"
								:uploadUrl="getUploadUrl('idCards')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,0,'idCards')"
								@successDeleteImg="successDeleteImg($event,'idCards')" />
						</view>
					</uni-section>
					<uni-section title="黑屏" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.blackScreen" :autoUpload="true"
								:uploadUrl="getUploadUrl('blackScreen')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,0,'blackScreen')"
								@successDeleteImg="successDeleteImg($event,'blackScreen')" />
						</view>
					</uni-section>
					<uni-section title="付款凭据" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.payment" :autoUpload="true"
								:uploadUrl="getUploadUrl('payment')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,0,'payment')"
								@successDeleteImg="successDeleteImg($event,'payment')" />
						</view>
					</uni-section>
					<uni-section title="其他" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataNotCash.others" :autoUpload="true"
								:uploadUrl="getUploadUrl('')" :deleteUrl="baseUrl+'sys/common/upload?token='+token"
								types="image" :uploadCount="20" @successImage="successImage($event,0,'others')"
								@successDeleteImg="successDeleteImg($event,'others')" />
						</view>
					</uni-section>
				</view>
				<view v-if="current === 'cash'">
					<uni-section title="授权书" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.authorization" :autoUpload="true"
								:uploadUrl="getUploadUrl('authorization')" :uploadCount="20"
								@successImage="successImage($event,1,'authorization')"
								@successDeleteImg="successDeleteImg($event,'authorization')" />
						</view>
					</uni-section>
					<uni-section title="确认单" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.confirmation" :autoUpload="true"
								:uploadUrl="getUploadUrl('confirmation')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,1,'confirmation')"
								@successDeleteImg="successDeleteImg($event,'confirmation')" />
						</view>
					</uni-section>
					<uni-section title="名单报" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.names" :autoUpload="true"
								:uploadUrl="getUploadUrl('names')" :deleteUrl="baseUrl+'sys/common/upload?token='+token"
								types="image" :uploadCount="20" @successImage="successImage($event,1,'names')"
								@successDeleteImg="successDeleteImg($event,'names')" />
						</view>
					</uni-section>
					<uni-section title="身份证复印件" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.idCards" :autoUpload="true"
								:uploadUrl="getUploadUrl('idCards')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,1,'idCards')"
								@successDeleteImg="successDeleteImg($event,'idCards')" />
						</view>
					</uni-section>
					<uni-section title="黑屏" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.blackScreen" :autoUpload="true"
								:uploadUrl="getUploadUrl('blackScreen')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,1,'blackScreen')"
								@successDeleteImg="successDeleteImg($event,'blackScreen')" />
						</view>
					</uni-section>
					<uni-section title="付款凭据" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.payment" :autoUpload="true"
								:uploadUrl="getUploadUrl('payment')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,1,'payment')"
								@successDeleteImg="successDeleteImg($event,'payment')" />
						</view>
					</uni-section>
					<uni-section title="其他" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataCash.others" :autoUpload="true"
								:uploadUrl="getUploadUrl('')" :deleteUrl="baseUrl+'sys/common/upload?token='+token"
								types="image" :uploadCount="20" @successImage="successImage($event,1,'others')"
								@successDeleteImg="successDeleteImg($event,'others')" />
						</view>
					</uni-section>
				</view>
				<view v-if="current === 'overSell'">
					<uni-section title="授权书" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.authorization"
								:autoUpload="true" :uploadUrl="getUploadUrl('authorization')" :uploadCount="20"
								@successImage="successImage($event,2,'authorization')"
								@successDeleteImg="successDeleteImg($event,'authorization')" />
						</view>
					</uni-section>
					<uni-section title="确认单" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.confirmation"
								:autoUpload="true" :uploadUrl="getUploadUrl('confirmation')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,2,'confirmation')"
								@successDeleteImg="successDeleteImg($event,'confirmation')" />
						</view>
					</uni-section>
					<uni-section title="名单报" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.names" :autoUpload="true"
								:uploadUrl="getUploadUrl('names')" :deleteUrl="baseUrl+'sys/common/upload?token='+token"
								types="image" :uploadCount="20" @successImage="successImage($event,2,'names')"
								@successDeleteImg="successDeleteImg($event,'names')" />
						</view>
					</uni-section>
					<uni-section title="身份证复印件" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.idCards" :autoUpload="true"
								:uploadUrl="getUploadUrl('idCards')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,2,'idCards')"
								@successDeleteImg="successDeleteImg($event,'idCards')" />
						</view>
					</uni-section>
					<uni-section title="黑屏" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.blackScreen" :autoUpload="true"
								:uploadUrl="getUploadUrl('blackScreen')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,2,'blackScreen')"
								@successDeleteImg="successDeleteImg($event,'blackScreen')" />
						</view>
					</uni-section>
					<uni-section title="付款凭据" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.payment" :autoUpload="true"
								:uploadUrl="getUploadUrl('payment')"
								:deleteUrl="baseUrl+'sys/common/upload?token='+token" types="image" :uploadCount="20"
								@successImage="successImage($event,2,'payment')"
								@successDeleteImg="successDeleteImg($event,'payment')" />
						</view>
					</uni-section>
					<uni-section title="其他" type="line">
						<view class="example-body">
							<easy-upload class="easy-upload" :dataList="formDataOverbook.others" :autoUpload="true"
								:uploadUrl="getUploadUrl('')" :deleteUrl="baseUrl+'sys/common/upload?token='+token"
								types="image" :uploadCount="20" @successImage="successImage($event,2,'others')"
								@successDeleteImg="successDeleteImg($event,'others')" />
						</view>
					</uni-section>
				</view>
			</view>
		</view>
		<!-- 签字显示的内容 -->
		<view class="uni-pb-15 sign01" v-if="currentMenuTab === '结算单签字'">
			<view class="uni-common-mt segmented-small" style="margin:0 10px;margin-top: 10rpx;">
				<uni-segmented-control key="signTab" :current="currentSignTab" :values="currentSignItems"
					style-type="button" active-color="#0c6eb7" @clickItem="onClickItemSignTab" />
			</view>
			<view class="uni-common-mt segmented-small" style="margin:0 10px;margin-top: 10rpx;"
				v-if="currentSignTab=='材料'">
				<uni-segmented-control key="signTabM" :current="currentSignTabMaterial"
					:values="currentSignItemsMaterial" style-type="text" active-color="#0c6eb7"
					@clickItem="onClickItemSignTabMaterial" />
			</view>
			<view class="content">
				<view>
					<uni-section title="基础信息" type="line">
						<view class="info uni-mlr-10">
							<view class="item"><text>航班号：</text>
								<view>{{signResultData.flightNo}}</view>
							</view>
							<view class="item"><text>航班日期：</text>
								<view>{{signResultData.flightDate}}</view>
							</view>
							<view class="item"><text>航空公司：</text>
								<view>{{getDisplayAirCompany()}}</view>
							</view>
							<view class="item"><text>飞机号：</text>
								<view>{{signResultData.planeNo}}</view>
							</view>
							<view class="item"><text>航线：</text>
								<view>{{signResultData.originC}} - {{signResultData.destC}}</view>
							</view>
							<view class="item"><text>机组人数：</text>
								<view>{{signResultData.cCount}}人</view>
							</view>
							<view class="item"><text>头等舱人数：</text>
								<view>{{signResultData.fOrVCount}}人</view>
							</view>
							<view class="item"><text>经济舱人数：</text>
								<view>{{signResultData.yCount}}人</view>
							</view>
							<view class="item"><text>提供服务理由：</text>
								<view v-if="currentSignTab !== '超售'">
									<text v-if="signResultData.reason&&signResultData.reason.length" style="width: initial;color: initial;padding: initial;margin: initial;border: none;">{{signResultData.reason}}。</text>{{signResultData.note}}
								</view>
								<view v-else>{{signResultData.note}}</view>
							</view>
						</view>
					</uni-section>
					<uni-section title="服务项目" type="line">
						<tempalte v-if="currentSignTab === '材料'">
							<view class="info uni-mlr-10" v-if="currentSignTabMaterial === '全员'">
								<view v-for="(value, key, index) in lstFeeMaterialall" :key="idx"
									v-if="lstFeeMaterialall">
									<view class="item" >
										<text>{{getLabel(key)}}：</text>
										<view><template v-if="getLabel(key)=='总计金额'">￥</template>{{ value }}</view>
									</view>
								</view>
								<!-- 签字列表 -->
								<view v-for="(item, index) in lstSign" :key="idx"
									v-if="lstSign">
									<view class="item" v-if="item.type==1"><text>制单人签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									<view class="item" v-if="item.type==2"><text>地面保障部签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									<view class="item" v-if="item.type==3"><text>航司签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									
								</view>
								
							</view>
							<view class="info uni-mlr-10" v-if="currentSignTabMaterial === '旅客'">
								<view v-for="(value, key, index) in lstFeeMaterialpsg" :key="idx"
									v-if="lstFeeMaterialpsg">
									<view class="item" >
										<text>{{getLabel(key)}}：</text>
										<view><template v-if="getLabel(key)=='总计金额'">￥</template>{{ value }}</view>
									</view>
								</view>
								<!-- 签字列表 -->
								<view v-for="(item, index) in lstSign" :key="idx"
									v-if="lstSign">
									<view class="item" v-if="item.type==1"><text>制单人签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									<view class="item" v-if="item.type==2"><text>地面保障部签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									<view class="item" v-if="item.type==3"><text>航司签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									
								</view>
							</view>
							<view class="info uni-mlr-10" v-if="currentSignTabMaterial === '机组'">
								<view v-for="(value, key, index) in lstFeeMaterialgrp" :key="idx"
									v-if="lstFeeMaterialgrp">
									<view class="item" >
										<text>{{getLabel(key)}}：</text>
										<view><template v-if="getLabel(key)=='总计金额'">￥</template>{{ value }}</view>
									</view>
								</view>
								<!-- 签字列表 -->
								<view v-for="(item, index) in lstSign" :key="idx"
									v-if="lstSign">
									<view class="item" v-if="item.type==1"><text>制单人签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									<view class="item" v-if="item.type==2"><text>地面保障部签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									<view class="item" v-if="item.type==3"><text>航司签字：</text>
										<image class="image" mode="widthFix"
											style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
											:src="'data:image/png;base64,'+item.sign" />
									</view>
									
								</view>
								
							</view>
						</tempalte>
						<view class="info uni-mlr-10" v-if="currentSignTab === '现金'">
							<view v-for="(value, key, index) in lstFeePay" :key="idx"
								v-if="lstFeePay">
								<view class="item" >
									<text>{{getLabel(key)}}：</text>
									<view><template v-if="getLabel(key)=='总计金额'">￥</template>{{ value }}</view>
								</view>
							</view>
							<!-- 签字列表 -->
							<view v-for="(item, index) in lstSign" :key="idx"
								v-if="lstSign">
								<view class="item" v-if="item.type==1"><text>制单人签字：</text>
									<image class="image" mode="widthFix"
										style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
										:src="'data:image/png;base64,'+item.sign" />
								</view>
								<view class="item" v-if="item.type==2"><text>地面保障部签字：</text>
									<image class="image" mode="widthFix"
										style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
										:src="'data:image/png;base64,'+item.sign" />
								</view>
								<view class="item" v-if="item.type==3"><text>航司签字：</text>
									<image class="image" mode="widthFix"
										style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
										:src="'data:image/png;base64,'+item.sign" />
								</view>
								
							</view>
						</view>
						<view class="info uni-mlr-10" v-if="currentSignTab === '超售'">
							<view v-for="(value, key, index) in lstFeeOversell" :key="idx"
								v-if="lstFeeOversell">
								<view class="item" >
									<text>{{getLabel(key)}}：</text>
									<view><template v-if="getLabel(key)=='总计金额'">￥</template>{{ value }}</view>
								</view>
							</view>
							<!-- 签字列表 -->
							<view v-for="(item, index) in lstSign" :key="idx"
								v-if="lstSign">
								<view class="item" v-if="item.type==1"><text>制单人签字：</text>
									<image class="image" mode="widthFix"
										style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
										:src="'data:image/png;base64,'+item.sign" />
								</view>
								<view class="item" v-if="item.type==2"><text>地面保障部签字：</text>
									<image class="image" mode="widthFix"
										style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
										:src="'data:image/png;base64,'+item.sign" />
								</view>
								<view class="item" v-if="item.type==3"><text>航司签字：</text>
									<image class="image" mode="widthFix"
										style="max-width: 120px;max-height: 90px; margin: 10px auto;display: block;"
										:src="'data:image/png;base64,'+item.sign" />
								</view>
								
							</view>
						</view>
					</uni-section>
					<uni-section :title="'请签字'+(companyCode&&companyCode.length?'（航司）':'')" type="line">
						<view class="uni-flex uni-m-5" style="padding: 12px 10px;padding-top: 0;"
							v-if="!(companyCode&&companyCode.length)">
							<text style="line-height: 24px;">签字人：</text>
							<uni-data-checkbox v-model="signRoleVal" :localdata="signRoleRange"
								@change="changeSignRole"></uni-data-checkbox>
						</view>
						<view class="example-body"
							style="border:dashed 1px #0c6eb7;margin: 0 10px;border-radius: 5px;height: 300px;position: relative;">
						<l-signature  disableScroll ref="signatureRef" penColor="black" :penSize="5"
														:openSmooth="false"></l-signature>
							
						</view>
						<view class="uni-flex uni-mt-5" style="justify-content: center;">
							<button class="uni-btn uni-btn-small" @click="onClickSign('clear')" size="mini">清空</button>
							<button class="uni-btn uni-btn-small" @click="onClickSign('save')" type="primary"
								size="mini">保存</button>
						</view>
					</uni-section>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import configService from '@/common/service/config.service.js';
	import {
		digitUppercase
	} from '@/common/luch-request/utils.js'
	export default {
		data() {
			return {
				upLoadImgUrl: configService.apiUrl + 'fd/image/add',
				deleteImgUrl: configService.apiUrl + 'fd/image/remove',
				url: {
					getFlightImage: '/flightImage/',
				},
				airImageUrl: '',
				token: '',
				data: {},
				toggleMoreInfo: false,
				items: ['非现金', '现金', '超售'],
				current: 'nonCash',
				dataList: [],
				formDataNotCash: {
					authorization: [],
					confirmation: [],
					names: [],
					idCards: [],
					blackScreen: [],
					payment: [],
					others: [],
				},
				formDataCash: {
					authorization: [],
					confirmation: [],
					names: [],
					idCards: [],
					blackScreen: [],
					payment: [],
					others: [],
				},
				formDataOverbook: {
					authorization: [],
					confirmation: [],
					names: [],
					idCards: [],
					blackScreen: [],
					payment: [],
					others: [],
				},
				// 签字相关
				menuTab: ['上传凭证', '结算单签字'],
				currentMenuTab: '上传凭证',
				currentSignItems: ['材料', '现金', '超售'],
				currentSignTab: '材料',
				currentSignItemsMaterial: ['全员', '旅客', '机组'],
				currentSignTabMaterial: '全员',
				queryAirSettlement: "/fd/queryAirSettlement",
				saveSignUrl: "/fd/airSettleSigns",
				signResultData: {},
				signRoleVal: 1,
				signRoleRange: [{
					"value": 1,
					"text": "制单人"
				}, {
					"value": 2,
					"text": "地面保障部"
				}],
				companyCode: null, //登录时存储的判断是否是航司用户登录的，有值就表示是航司用户,
				lstFeeMaterialall: null, //材料-全员
				lstFeeMaterialpsg: null, //材料-旅客
				lstFeeMaterialgrp: null, //材料-机组
				lstFeePay: null, //现金
				lstFeeOversell: null, //超售
				lstSign:null,//签字图
				

			}
		},
		onLoad(e) {
			this.token = uni.getStorageSync('token') || 'd057c74841e7460e81bed9388301d816'
			this.companyCode = uni.getStorageSync('companyCode');
			
			if (e.data) {
				this.data = JSON.parse(e.data);
				if (this.data.airImage) {
					this.getAirImage(this.data.airImage)
				}
				console.log(this.data)
				// 航司用户，只显示 结算单签字，不用显示上传凭证菜单
				if(this.companyCode&&this.companyCode.length){
					this.currentMenuTab = '结算单签字',
					this.getInfoData()
				}else{
					this.setImgUrl()
				}
				
			}
		},
		
		methods: {
			setImgUrl() {
				// console.log(this.data.cashImageLst);
				if (this.data.nonCashImageLst.length) {
					this.formDataNotCash.authorization = this.data.nonCashImageLst.filter(image => image.type ===
						'authorization') || [];
					this.formDataNotCash.confirmation = this.data.nonCashImageLst.filter(image => image.type ===
						'confirmation') || [];
					this.formDataNotCash.names = this.data.nonCashImageLst.filter(image => image.type === 'names') || [];
					this.formDataNotCash.idCards = this.data.nonCashImageLst.filter(image => image.type === 'idCards') ||
					[];
					this.formDataNotCash.blackScreen = this.data.nonCashImageLst.filter(image => image.type ===
						'blackScreen') || [];
					this.formDataNotCash.payment = this.data.nonCashImageLst.filter(image => image.type === 'payment') ||
					[];
					this.formDataNotCash.others = this.data.nonCashImageLst.filter(image => image.type === '') || [];
				}
				if (this.data.cashImageLst.length) {
					this.formDataCash.authorization = this.data.cashImageLst.filter(image => image.type ===
						'authorization') || [];
					this.formDataCash.confirmation = this.data.cashImageLst.filter(image => image.type ===
						'confirmation') || [];
					this.formDataCash.names = this.data.cashImageLst.filter(image => image.type === 'names') || [];
					this.formDataCash.idCards = this.data.cashImageLst.filter(image => image.type === 'idCards') || [];
					this.formDataCash.blackScreen = this.data.cashImageLst.filter(image => image.type === 'blackScreen') ||
						[];
					this.formDataCash.payment = this.data.cashImageLst.filter(image => image.type === 'payment') || [];
					this.formDataCash.others = this.data.cashImageLst.filter(image => image.type === '') || [];
				}
				if (this.data.overSellImageLst.length) {
					this.formDataOverbook.authorization = this.data.overSellImageLst.filter(image => image.type ===
						'authorization') || [];
					this.formDataOverbook.confirmation = this.data.overSellImageLst.filter(image => image.type ===
						'confirmation') || [];
					this.formDataOverbook.names = this.data.overSellImageLst.filter(image => image.type === 'names') || [];
					this.formDataOverbook.idCards = this.data.overSellImageLst.filter(image => image.type === 'idCards') ||
						[];
					this.formDataOverbook.blackScreen = this.data.overSellImageLst.filter(image => image.type ===
						'blackScreen') || [];
					this.formDataOverbook.payment = this.data.overSellImageLst.filter(image => image.type === 'payment') ||
						[];
					this.formDataOverbook.others = this.data.overSellImageLst.filter(image => image.type === '') || [];
				}
				// console.log(this.formDataCash);
			},
			getUploadUrl(type) {
				return this.upLoadImgUrl + '?token=' + this.token + '&type=' + type + '&tab=' + this.current +
					'&flightId=' + this.data.flightId
			},
			getDeleteUrl(imageId) {
				return this.deleteImgUrl + '?token=' + this.token + '&tab=' + this.current + '&imageId=' + imageId +
					'&flightId=' + this.data.flightId
			},
			successImage(e, tabIdx, fieldName) {
				//debugger;
				console.log(e, JSON.parse(e.data), tabIdx, fieldName);
				// console.log(this.dataList);
				let uploadResult = JSON.parse(e.data)
				// console.log(uploadResult);
				if (uploadResult.errcode == 0) {
					if (uploadResult.data.tab == 'nonCash') {
						// console.log("nonCash")
						this.formDataNotCash[fieldName].push(uploadResult.data.images[0])
						// console.log(this.formDataNotCash[fieldName])
					} else if (uploadResult.data.tab == 'cash') {
						this.formDataCash[fieldName].push(uploadResult.data.images[0])
					} else if (uploadResult.data.tab == 'overSell') {
						this.formDataOverbook[fieldName].push(uploadResult.data.images[0])
					}
				} else {
					uni.showToast({
						title: uploadResult.errmsg,
						icon: "none"
					})
				}
			},
			successDeleteImg(imgId, type) {
				// console.log(22, imgId);

				this.$http.post(this.deleteImgUrl, {
					token: this.token,
					flightId: this.data.flightId,
					tab: this.current,
					imageId: imgId
				}).then(res => {
					// console.log(res)
					if (res.data.errcode == 0) {
						// me.newsList=res.data.result.records
						if (this.current == 'nonCash') {
							this.formDataNotCash[type] = this.formDataNotCash[type].filter(item => item.id !=
								imgId)
						} else if (this.current == 'cash') {
							this.formDataCash[type] = this.formDataCash[type].filter(item => item.id != imgId)
						} else if (this.current == 'overSell') {
							this.formDataOverbook[type] = this.formDataOverbook[type].filter(item => item.id !=
								imgId)
						}

						uni.showToast({
							title: '删除成功',
							icon: "success"
						})
					} else {
						uni.showToast({
							title: res.data.errmsg,
							icon: "none"
						})
					}
				})
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					if (e.currentIndex == 0) {
						this.current = 'nonCash'
					} else if (e.currentIndex == 1) {
						this.current = 'cash'
					} else if (e.currentIndex == 2) {
						this.current = 'overSell'
					}
				}
			},
			// 获取航司Logo图片
			getAirImage(url) {
				if (url && url.length) {
					let split = url.split('/')
					let flatN = split[split.length - 1]
					let me = this
					uni.request({
						url: configService.apiUrl.replace(/\/m\//, '') + this.url.getFlightImage + flatN,
						responseType: "arraybuffer",
						success: async function(res) {
							let datas = res.data
							//将arrayBuffer数据转换成base64格式即可显示 
							me.airImageUrl = `data:image/jpeg;base64,${uni.arrayBufferToBase64(datas)}`
							// console.log(me.airImage);
							return me.airImageUrl
						},
					})
				}


			},
			// 签字相关
			onClickItemMenuTab(e) {
				if (this.currentMenuTab !== e.currentIndex) {
					if (e.currentIndex == 0) {
						this.currentMenuTab = '上传凭证'
						this.currentSignTab = '材料'
						this.currentSignTabMaterial = '全员'
					} else if (e.currentIndex == 1) {
						this.currentMenuTab = '结算单签字'
						this.getInfoData()
					}
				}
			},
			async getInfoData() {
				// this.currentSignItems = '材料'
				let me = this
				await this.$http.post(this.queryAirSettlement, {
					flightId: this.data.flightId,
					token: this.token
				}).then(res => {
					// console.log(res)
					if (res.data.errcode == 0) {
						// Object.assign(this.signResultData, res.data.data);
						me.signResultData = res.data.data
						if (me.signResultData.lstFee.materialall) me.lstFeeMaterialall =  me.sortServiceFee(me.signResultData.lstFee.materialall)
						if (me.signResultData.lstFee.materialpsg) me.lstFeeMaterialpsg = me.sortServiceFee(me.signResultData.lstFee.materialpsg)
						if (me.signResultData.lstFee.materialgrp) me.lstFeeMaterialgrp = me.sortServiceFee(me.signResultData.lstFee.materialgrp)
						if (me.signResultData.lstFee.pay) me.lstFeePay = me.sortServiceFee(me.signResultData.lstFee.pay)
						if (me.signResultData.lstFee.oversell) me.lstFeeOversell = me.sortServiceFee(me.signResultData.lstFee.oversell)
						me.lstSign = me.signResultData.lstSign
						// console.log(me.signResultData);
						// console.log(me.lstFeeMaterialpsg);
					} else {
						uni.showToast({
							title: res.data.errmsg,
							icon: "none"
						})
					}
				})
				// this.signResultData = {
				// 	logo:'',
				// 	serCompanyName:'serCompanyName', //航司名称(用于水印文本内容)
				// 	flightNo:'flightNo',//航班号
				// 	flightDate:'flightDate',//航班日期
				// 	airCompany:'airCompany',//航空公司
				// 	planeNo:'planeNo',//航班号
				// 	route:'route',//航线
				// 	cgCount:'cgCount',//机组人数
				// 	fOrVCount :'fOrVCount ',//头等舱人数
				// 	yCount:'yCount',//经济舱人数
				// 	reason:'reason',//提供服务理由 reason:'reason',//材料/现金时：提供服务理由 = reason + "。" + note;超售时:提供服务理由 = note;
				// 	note:'note',//提供服务理由
				// lstSign:[],  //签字信息列表	List<Signature2>

				// 	lstFee:{} //服务项目列表列表 HashMap<String,HashMap<>>
				// }

				// this.currentSignItems = this.currentSignItems.splice(0,this.signResultData.lstFee.length)
			},
			sortServiceFee(originList){
				const order = ['drink', 'breakfast', 'lunch','dinner', 'night', 'hotel','car', 'pay', 'memo', 'totalPrice']; // 定义显示顺序
				const sorted = {};
				
				// 按指定顺序添加属性
				order.forEach(key => {
								if (originList[key] !== undefined) {
								  sorted[key] = originList[key];
								}
				});
				
				// 添加未在顺序列表中的其他属性
				Object.keys(originList).forEach(key => {
								if (!order.includes(key)) {
								  sorted[key] = originList[key];
								}
				});
				
				return sorted;
			},
			async onClickSign(type) {
				let me = this
				if (type == 'save') {
					this.$refs.signatureRef.canvasToTempFilePath({
						success: (res) => {
							// 是否为空画板 无签名
							console.log(res.isEmpty)
							console.log(res)
							// 微信小程序-生成图片的临时路径
							// 执行图片转base64方法
							this.base64(res.tempFilePath, "png").then(res => {
								// console.log(res, 'base64路径') //res是base64路径
								this.url = res

								let params = {
									type: (this.companyCode && this.companyCode.length) ? 3 :
										this.signRoleVal, //1：制单人签字 2:地面保障部签字 3：航司签字
									flightIds: this.data.flightId,
									signature: res,
									token:this.token
									// imageBase64: this.url
								}
								console.log(params) //res是base64路径
								try{
									this.$http.post(this.saveSignUrl, params).then(res => {
										// console.log(res)
										if (res.data.errcode == 0) {
											uni.showToast({
												title: '保存成功',
												icon: "success"
											})
											me.getInfoData()
											me.$refs.signatureRef.clear()
										} else {
											uni.showToast({
												title: res.data.errmsg,
												icon: "none"
											})
										}
									})
								}catch(e){
									//TODO handle the exception
									uni.showToast({
										title: "程序错误",
										icon: "none"
									})
								}
								
							})

						}
					})

				} else {
					this.$refs.signatureRef.clear()

				}
			},
			// 图片转64
			base64(url, type) {
				return new Promise((resolve, reject) => {
					wx.getFileSystemManager().readFile({
						filePath: url, //选择图片返回的相对路径
						encoding: 'base64', //编码格式
						success: res => {
							// resolve('data:image/' + type.toLocaleLowerCase() + ';base64,' + res.data)
							resolve(res.data)
						},
						fail: res => reject(res.errMsg)
					})
				})
			},
			changeSignRole(e) {
				console.log('e:', e);
				if(e.detail.value != this.signRoleVal){
					this.$refs.signatureRef.clear()
				}
				this.signRoleVal = e.detail.value
			},
			onClickItemSignTab(e) {
				if (this.currentSignTab !== e.currentIndex) {
					if (e.currentIndex == 0) {
						this.currentSignTab = '材料'
					} else if (e.currentIndex == 1) {
						this.currentSignTab = '现金'
					} else if (e.currentIndex == 2) {
						this.currentSignTab = '超售'
					}
				}
			},
			onClickItemSignTabMaterial(e) {
				if (this.currentSignTabMaterial !== e.currentIndex) {
					if (e.currentIndex == 0) {
						this.currentSignTabMaterial = '全员'
					} else if (e.currentIndex == 1) {
						this.currentSignTabMaterial = '旅客'
					} else if (e.currentIndex == 2) {
						this.currentSignTabMaterial = '机组'
					}

				}
			},
			getLabel(key) {
			      const labels = {
			        drink: '饮料费',
			        breakfast: '早餐费',
			        lunch: '午餐费',
			        dinner: '晚餐费',
			        night: '夜宵/点心',
			        hotel: '住宿费',
			        car: '地面交通费',
			        pay: '补偿费',
			        memo: '备注',
			        totalPrice: '总计金额',
			      }
			      return labels[key] || key // 如果找不到映射，返回原始键名
			    },
			// 根据当前tab状态获取显示的航空公司名称
			getDisplayAirCompany() {
				// 检查数据是否已加载
				if (!this.signResultData || !this.signResultData.airCompany) {
					return '-';
				}
				
				// 如果是机组，显示原始航空公司名称
				if (this.currentSignTab === '材料' && this.currentSignTabMaterial === '机组') {
					return this.signResultData.airCompany;
				}
				
				// 如果是中国南方航空股份有限公司，显示为北方分公司
				if (this.signResultData.airCompany === '中国南方航空股份有限公司') {
					return '中国南方航空股份有限公司北方分公司';
				}
				
				// 其他情况显示原始航空公司名称
				return this.signResultData.airCompany;
			}
		}
	}
</script>

<style lang="scss">


</style>